package br.nextfm.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.nextfm.dao.UsuarioDao;
import br.nextfm.model.Comum;

public class ControlaUsuario extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String action = request.getParameter("action");
		
		int id = Integer.parseInt(request.getParameter("id"));
		
		UsuarioDao dao = new UsuarioDao();
		Comum comum = dao.getComum(id);
		
		if (action.equals("bloquear")) {
			comum.setEstado(1);
		}
		else {
			comum.setEstado(0);
		}
		
		dao.update(comum);
		
		request.setAttribute("usuarios", dao.getAllComuns());
		request.getRequestDispatcher("comum.jsp").forward(request, response);
		
	}

}
